package com.hp.controller;

import com.hp.entity.books;
import com.hp.result.DataGridResultInfo;
import com.hp.result.SubmitResultInfo;
import com.hp.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.Map;

/**
 * 所有的数据返回都要求统一
 * 1.统一异常处理
 * 2.权限过滤
 * 3.规范化-国际化.异常消息通知定义
 * 4.不用关心前台
 */
//@Controller

@Controller
@RequestMapping("/links")
public class LinkController {//springmvc去扫描

    @Autowired
    private BookService bookService;//bean spring容器去扫描 父子 bean controller
    /**
     * 查询所有
     * @return
     */
    @RequestMapping("/querylink_result")
    @ResponseBody
    public DataGridResultInfo querybusiness_result(
            @RequestParam(name = "page", defaultValue = "1") int page,
            @RequestParam(name = "rows", defaultValue = "10") int rows) throws Exception {

        return bookService.findlinkList(page, rows);

    }

    /**
     * 去查询页面
     */
    @RequestMapping(value = "/querylink")
    public String querylink(){
        System.out.println("1tfvfgvgvvvvvvvvvvvvv++++++++++++++++++++++++++++++++++++++++++");
        return "link/querylink";
    }

    /**
     * 删除
     * @param
     * @return
     */

    @RequestMapping("/deletetype")
    @ResponseBody
    public SubmitResultInfo deletetype(@RequestParam("bookid")String bookid) throws Exception {
        System.out.println(bookid);
        return  bookService.deletetype(bookid);
    }

    @RequestMapping("/editlink")
    public String editlink(@RequestParam("bookid")String bookid, Map<String,Object>map)throws Exception{
        books book=bookService.findById(bookid);
        map.put("link",book);
        System.out.println("==============="+book.getBookname());
        return "link/editlink";
    }

    @RequestMapping("/aaaaaa")
    @ResponseBody
    public SubmitResultInfo editlinksubmit(books book)throws Exception{
        return  bookService.updateLink(book);
    }

    @RequestMapping("/bbb")
    @ResponseBody
    public SubmitResultInfo bbb(books book)throws Exception{
        return bookService.add(book);
    }


    /**
     * 去修改页面
     * @param id
     * @return
     * @throws Exception
     * model modelMap Map modelAndView Requset Session Writer
     *
     *//*
    @RequestMapping("/editlink")
    public String editlink(String id,Map<String,Object> map) throws Exception{
        Link link=linkService.findById(id);
        map.put("link", link);
        return "link/editlink";
    }

    *//**
     * 修改链接
     * @return
     * @throws Exception
     *//*
    @RequestMapping(value="/editlinksubmit",method=RequestMethod.POST)
    @ResponseBody
    public SubmitResultInfo editlinksubmit(Link link) throws Exception{
        linkService.updateLink(link);

        return ResultUtil.createSubmitResult(ResultUtil.createSuccess(Config.MESSAGE,666,new Object[]{}));
    }*/


}
